Stronger user token generation
[lhc/web/wiklou.git] / config / installer.php
1 <?php
2
3 # MediaWiki web-based config/installation
4 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5 # http://www.mediawiki.org/
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # http://www.gnu.org/copyleft/gpl.html
21
22
23 /**
24 * This is to be the fancy new installer package for MediaWiki,
25 * which will work with table prefixes, both MySQL and PostgreSQL, and
26 * ideally such wacky things as text-based install as well as web.
27 *
28 * It's not done yet.
29 *
30 * @todo finish...
31 * @package MediaWiki
32 * @subpackage Installer
33 */
34
35 $IP = ".."; # Just to suppress notices, not for anything useful
36 define( "MEDIAWIKI", true );
37 define( "MEDIAWIKI_INSTALL", true );
38 require_once( "../includes/Defines.php" );
39 require_once( "../includes/DefaultSettings.php" );
40 require_once( "../includes/MagicWord.php" );
41 require_once( "../includes/Namespace.php" );
42 require_once( "../install-utils.inc" );
43 require_once( "../maintenance/updaters.inc" );
44 require_once( "../maintenance/convertLinks.inc" );
45 require_once( "../maintenance/archives/moveCustomMessages.inc" );
46
47 class InstallInterface {
48 function message( $text ) {
49 echo $text . "\n";
50 }
51
52 function warning( $text ) {
53 echo "** $text **\n";
54 }
55
56 function formatLink( $url, $text = '' ) {
57 if( $text ) {
58 return "$text ($url)";
59 } else {
60 return $url;
61 }
62 }
63
64 function showHeader() {
65 global $wgVersion;
66 echo "MediaWiki $wgVersion installation\n\n";
67 }
68 }
69
70 class Installer {
71 var $settings = array();
72
73 function Installer( &$interface ) {
74 $this->ui =& $interface;
75 }
76
77 function runInstall() {
78 $this->ui->showHeader();
79 $this->preInstallChecks();
80 }
81
82 function override( $var, $value ) {
83 $this->settings[$var] = $value;
84 }
85
86 function preInstallChecks() {
87 $checks = array(
88 'checkConfigured',
89 'checkInstalled',
90 'checkWritable',
91 'checkPHP',
92 'checkGlobals',
93 'checkSafeMode',
94 'checkSAPI',
95 'checkMemory',
96 'checkZlib',
97 'checkImageMagick',
98 'checkGD'
99 );
100 foreach( $checks as $check ) {
101 if( !$this->$check() ) {
102 $this->ui->warning( "Installation aborted." );
103 return false;
104 }
105 }
106 }
107
108 function checkConfigured() {
109 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
110 $this->ui->warning( "Already configured." );
111 return false;
112 }
113 return true;
114 }
115
116 function checkInstalled() {
117 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
118 $this->ui->warning( "Already configured; move LocalSettings.php from this directory to the parent dir and take the wiki for a spin." );
119 return false;
120 }
121 return true;
122 }
123
124 function checkWritable() {
125 if( !is_writable( "." ) ) {
126 $this->ui->warning( "<h2>Can't write config file, aborting</h2>
127
128 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
129 writable by the web server. Once configuration is done you'll move the created
130 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
131 then remove the <tt>config</tt> subdirectory entirely.</p>
132
133 <p>To make the directory writable on a Unix/Linux system:</p>
134
135 <pre>
136 cd <i>/path/to/wiki</i>
137 chmod a+w config
138 </pre>" );
139
140 return false;
141 }
142 return true;
143 }
144
145 function checkPHP() {
146 $ver = phpversion();
147 if( version_compare( $ver, "4.1.2", "lt" ) ) {
148 $this->ui->warning( "Your version of PHP ($ver) is too old and will probably not work. We try to support 4.1.2 and above, but a current 4.3 or 5.0 release is preferred." );
149 return false;
150 }
151 $this->ui->message( "PHP version $ver, ok" );
152 if( version_compare( $ver, "gte", "5.0" ) ) {
153 $this->ui->warning( "A PHP5-compatible version of the PHPTAL template system is not yet bundled. To get the regular default page layout, you will need to manually install a development snapshot. (The wiki will function normally using an older layout if you do not.)" );
154 }
155 return true;
156 }
157
158 function checkGlobals() {
159 if( ini_get( 'register_globals' ) ) {
160 $this->ui->warning( "PHP's " .
161 $this->ui->formatLink( "http://php.net/register_globals", "register_globals" ) .
162 "option is enabled." .
163 "MediaWiki will work correctly, but this setting
164 increases your exposure to potential security vulnerabilities in PHP-based
165 software running on your server. <b>You should disable it if you are able.</b>" );
166 }
167 return true;
168 }
169
170 function checkSafeMode() {
171 if( ini_get( 'safe_mode' ) ) {
172 $this->ui->warning( "PHP's
173 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
174 You will likely have problems caused by this. You may need to make the
175 'images' subdirectory writable or specify a TMP environment variable pointing to
176 a writable temporary directory owned by you, since safe mode breaks the system
177 temporary directory." );
178 $this->ui->message( "...due to safe mode restrictions, uploads will use flat directory mode if enabled." );
179 $this->override( 'wgHashedUploadDirectory', true );
180 } else {
181 $this->ui->message( "PHP is not running in safe mode (this is good!)" );
182 $this->ui->message( "...uploads will use hashed directory tree mode if enabled." );
183 }
184 return true;
185 }
186
187 function checkSAPI() {
188 $sapi = php_sapi_name();
189 $this->ui->message( "PHP server API is $sapi..." );
190 switch( $sapi ) {
191 case "apache":
192 case "apache2handler":
193 $this->ui->message( "...ok, using pretty URLs (<tt>index.php/Page_Title</tt>)" );
194 break;
195 case "cgi":
196 case "cgi-fcgi":
197 case "apache2filter":
198 $this->ui->message( "using ugly URLs (<tt>index.php?title=Page_Title</tt>)" );
199 $this->override( 'prettyURLs', false );
200 # FIXME
201 break;
202 default:
203 $this->ui->message( "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>" );
204 }
205 return true;
206 }
207
208 function checkMemory() {
209 $memlimit = ini_get( "memory_limit" );
210 if( empty( $memlimit ) ) {
211 $this->ui->message( "PHP is configured with no <tt>memory_limit</tt>." );
212 return true;
213 } else {
214 $this->ui->message( "PHP's <tt>memory_limit</tt> is $memlimit... " );
215 $n = IntVal( $memlimit );
216 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
217 $n = IntVal( $m[1] * (1024*1024) );
218 }
219 if( $n < 20*1024*1024 ) {
220 if( false === ini_set( "memory_limit", "20M" ) ) {
221 $this->ui->warning( "...failed to raise the limit to 20M; you may have problems" );
222 } else {
223 $this->ui->message( "...raising limit to 20M" );
224 $this->override( 'raiseMemory', true );
225 }
226 }
227 return true;
228 }
229 }
230
231 function checkZlib() {
232 $zlib = function_exists( "gzencode" );
233 if( $zlib ) {
234 $this->ui->message( "Have zlib support; enabling output compression." );
235 # This is a runtime thing, we're just letting the user know about it?
236 } else {
237 $this->ui->message( "No zlib support." );
238 }
239 return true;
240 }
241
242 function checkImageMagick() {
243 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
244 foreach( $imcheck as $dir ) {
245 $im = "$dir/convert";
246 if( file_exists( $im ) ) {
247 $this->ui->message( "Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads." );
248 $this->override( "wgImageMagick", $im );
249 $this->override( "wgUseImageResize", true );
250 break;
251 }
252 }
253 return true;
254 }
255
256 function checkGD() {
257 $gd = function_exists( "imagejpeg" );
258 if( $gd ) {
259 $this->ui->message( "Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads" );
260 $this->override( "wgUseImageResize", true );
261 } else {
262 if( !isset( $this->settings['wgUseImageResize'] ) ) {
263 $this->warning( "Couldn't find GD library or ImageMagick; image thumbnailing disabled." );
264 }
265 }
266 return true;
267 }
268
269
270 }
271
272 $ui =& new InstallInterface();
273 $i =& new Installer( $ui );
274 $i->runInstall();
275
276 ?>